<?php

namespace app\model\blog;

use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;

class Article
{

    /**
     * 查询分类条数
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public static function getArticleClassifyData(): array
    {
        $sql = Db::table(ArticleTable)
            ->where(['status' => 1])
            ->field(['classify_id', 'count(id) as number'])
            ->group('classify_id')
            ->buildSql();

        return Db::table(ArticleClassifyTable)
            ->alias('ac')
            ->leftJoin([$sql => 'a'], 'ac.id = a.classify_id')
            ->field(['ac.id', 'ac.name', 'a.number'])
            ->select()
            ->toArray();
    }

}
